#include<bits/stdc++.h>
#define XH(i,a,b) for(int i=a;i<b;++i)
#define XXH(i,a,b) for(int i=a-1;i>=b;--i)
#define LL long long
using namespace std;
int tmpINT; string tmpSTRING; char tmpCHAR; double tmpDOUBLE; LL tmpLONGLONG;

void solve(){
    int a,b,k;scanf("%d%d%d", &a,&b,&k);
    LL boy[k];
    for (int i = 0 ; i < k ; ++i){
        scanf("%I64d", &boy[i]);
    }
    LL girl[k];
    for (int i = 0; i < k; ++i){
        scanf("%I64d", &girl[i]);
    }
    vector<LL>boyindex(a+1,0),girlindex(b+1,0);
    for (int i = 0 ; i < k ; ++i)
    {
        ++boyindex[boy[i]];
        ++girlindex[girl[i]];
    }
    LL ans = k*(k-1)/2;
    for (int i = 1 ; i < a+1 ; ++i)
    {
        if(boyindex[i]>=2){
            ans -= boyindex[i]*(boyindex[i]-1)/2;
        }
    }
    for (int i = 1 ; i < b+1 ; ++i)
    {
        LL num = girlindex[i];
        if(num>1){
            ans -= num*(num-1)/2;
        }
    }
    printf("%I64d\n", ans);
}

int main(){
    int t;scanf("%d",&t);
    for(int i = 0; i < t; ++i){
        solve();
    }

    return 0;
}
